using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using RobotSimulator.Basic;

public class BasicInput : BasicPublisher
{
    float x;
    float y;
    float h;
    float r;
    public float speed;
    protected override void Start()
    {
        base.Start();
        this.control_target =this.control_target.GetComponent<FourRotorController>();
        Debug.Log(Input.GetJoystickNames()[0]);
    }
    private void Update()
    {
        x = Input.GetAxis("Horizontal") * 15f;
        h += Time.deltaTime * speed * Input.GetAxis("Vertical");
        r -= Time.deltaTime * speed * Input.GetAxis("HorizontalR");
        y = Input.GetAxis("VerticalR") * 15f;
        if (h < -1)
        {
            h = -1;
        }

        //x = Input.GetAxis("Horizontal");
        //h = Input.GetAxis("Vertical");
        //r = Input.GetAxis("HorizontalR");
        //y = Input.GetAxis("VerticalR");
        Debug.Log($"r:{r},h:{h},x:{x},y:{y}");
        //Debug.Log(Input.GetAxis("JOYTEST"));
        //if (Input.GetKey(KeyCode.W))
        //{
        //    Input.GetAxis("Horizontal");

        //}
        //if (Input.GetKey(KeyCode.S))
        //{
        //    h -= Time.deltaTime* speed;
        //}
        //if (Input.GetKey(KeyCode.A))
        //{
        //    r= Time.deltaTime* speed*10f;
        //}
        //if (Input.GetKey(KeyCode.D))
        //{
        //    r -= Time.deltaTime*speed*10f;
        //}
        //if (Input.GetKey(KeyCode.UpArrow))
        //{
        //    y += Time.deltaTime * speed*10f;
        //}
        //if (Input.GetKey(KeyCode.DownArrow))
        //{
        //    y -= Time.deltaTime * speed * 10f;
        //}
        //if (Input.GetKey(KeyCode.LeftArrow))
        //{
        //    x += Time.deltaTime * speed * 10f;
        //}
        //if (Input.GetKey(KeyCode.RightArrow))
        //{
        //    x -= Time.deltaTime * speed * 10f;
        //}
    }
    protected override void Loop()
    {
        base.Loop();
        this.control_target.RecvCmd(new CmdAutoFourRotorControl(x, y, r, h));
    }
}
